package com.myjpa;

import com.myjpa.common.criteria.CriteriaUtils;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.ConfigurableEnvironment;

import javax.persistence.EntityManager;
import java.util.Map;

/**
 * @author: yaoll
 * @date: 2020-09-04
 * @verison: 1.0
 */
@Slf4j
@SpringBootApplication
public class App05 {

	public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(App05.class, args);
		ConfigurableEnvironment env = context.getEnvironment();

		String[] activeProfiles = env.getActiveProfiles();

		for (String activeProfile : activeProfiles) {
			log.info("================== active profiles: {}", activeProfile);
		}

		Map<String, Object> systemEnvironment = env.getSystemEnvironment();
		systemEnvironment.forEach((key, value) -> {
			log.info("================== system environment : {} = {}", key, value);
		});
	}

	@Bean
	public JPAQueryFactory jpaQueryFactory(EntityManager entityManager) {
		return new JPAQueryFactory(entityManager);
	}

	@Bean
	public CriteriaUtils criteriaUtils(@Autowired JPAQueryFactory jpaQueryFactory) {
		return new CriteriaUtils(jpaQueryFactory);
	}
}